package com.yue92.datalife.common;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MultiDatabaseAop {

    @Pointcut("execution(* com.yue92.datalife.repository.*.find*(..))")
    public void pointcutFind() {
    }

    @Before("pointcutFind()")
    public void beginMulti() {
        DatabaseContextHolder.setType(DatabaseContextHolder.TYPE_SLAVE);
    }

    @After("pointcutFind()")
    public void commit() {
        DatabaseContextHolder.clearType();
    }

}
